#pragma once

#include <iostream>
#include <pthread.h>
#include"Mutex.hpp"

namespace Cond_Module
{

    using namespace Lock_Module;

    class Cond
    {
    private:
        pthread_cond_t _cond;

    public:
        Cond()
        {
            int n = ::pthread_cond_init(&_cond, NULL);
            if (n != 0)
            {
                std::cout << "Cond init error" << std::endl;
            }
        }

        void wait(Mutex& mutex)
        {
            int n = ::pthread_cond_wait(&_cond, mutex.getMutex());
        }
        void Notify()
        {
            int n = ::pthread_cond_signal(&_cond);
        }
        void NotifyAll()
        {
            int n = ::pthread_cond_broadcast(&_cond);
        }
        ~Cond()
        {
            int n = ::pthread_cond_destroy(&_cond);
        }
    };
}